package com.ganbo.thread.singleton;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by gan on 2020/5/21 22:39.
 */
public enum EnumeSingletonDemo {


    connectionFactory;

    private Connection connection;


    EnumeSingletonDemo() {
        System.out.println("调用了构造函数");
        String url = "jdbc.....";

        try {
            Class.forName("com.jdbc.mysql.Diver");
            connection = DriverManager.getConnection(url, "root", "root");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


    public Connection getConnection() {
        return connectionFactory.connection;
    }


    public static void main(String[] args) {
        Connection connection = EnumeSingletonDemo.connectionFactory.getConnection();
    }
}
